package thinkingJava.chapter12;
class MyException2 extends Exception {
	private static final long serialVersionUID = -9094880404067136770L;
	private int x;
	public MyException2() {}
	public MyException2(String msg) {
		super(msg);
	}
	public MyException2(String msg ,int x) {
		super(msg);
		this.x = x;
	}
	public int val() {
		return x;
	}
	public String getMessage() {
		return "Detail message : " + x + "  " + super.getMessage();
	}
}
public class ExtraFeatures {
	public static void f() throws MyException2 {
		System.out.println("throws Exception in f()");
		throw new MyException2();
	}
	public static void g() throws MyException2 {
		System.out.println("throws MyException2 in g() with message");
		throw new MyException2("Exception occured!");
	}
	public static void h() throws MyException2 {
		System.out.println("throws MyException2 in h() with message and x");
		throw new MyException2("Exception happened with number",1);
	}
	public static void main(String[] args) {
		try {
			f();
		} catch (MyException2 e) {
			e.printStackTrace(System.out);
		}
		try {
			g();
		} catch (MyException2 e) {
			e.printStackTrace(System.out);
		}
		try {
			h();
		} catch (MyException2 e) {
			e.printStackTrace(System.out);
			System.out.println("e.val() = " + e.val());
		}

	}
}
